/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code6 {
    //二叉树的所有路径
    public List<String> ret;
    public void dfs(TreeNode root,StringBuffer _path) {
        //出口 
        if(root==null) return;

        StringBuffer path = new StringBuffer(_path);//形参
        path.append(Integer.toString(root.val));
        //下面都是空的时候加
        if(root.left==null&&root.right==null) {
            ret.add(path.toString());
            return;
        }
        path.append("->");
        dfs(root.left,path);
        dfs(root.right,path);

    }
    public List<String> binaryTreePaths(TreeNode root) {
        ret = new ArrayList<>();
        dfs(root,new StringBuffer());
        return ret;
    }
}